package com.juc.scheduledExecutorService.scheduledExecutorService11;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Run1_ext {

	/**
	 * 总结如下
	 * 1.在队列中的任务可以取消，任务也不在运行
	 * 2.正在运行的任务可以停止 但要结合if(Thread.currentThread().isInterrupted()==true)
	 * 判断
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws InterruptedException {
		ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
		Runnable runnable1 = new MyRunnable("A");
		//第二个参数为0则任务不放入队列中马上运行
		ScheduledFuture<?> feFuture = executor.schedule(runnable1, 0, TimeUnit.SECONDS);
		Thread.sleep(1000);
		BlockingQueue<Runnable> queue = executor.getQueue();
		System.out.println("A处size() = " +queue.size());
		System.out.println("取消结果为 ： " + feFuture.cancel(true));
		queue = executor.getQueue();
		System.out.println("B处size() = " +queue.size());
		System.out.println("main end !");
	}
}
